package com.zhaokuner.springcloudconfigserver.webhook;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * <p>
 * Description:刷新
 * <p>
 * Copyright: 2018-现在 北京掌通未来科技有限公司
 * <p>
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/7/24 12:01
 */
@RestController
@RequestMapping("/webHook")
@Log4j2
public class WebHooksCtrl {

    @Autowired
    private WebHooksService webHooksService;

    @RequestMapping("/refresh/{git}")
    public Object root(@RequestBody JSONObject obj, @PathVariable String git) {
        HashMap<String, WebHookModel> modelHashMap;
        if (null == git) {
            git = "";
        }
        switch (git) {
            case "gitee":
                modelHashMap = webHooksService.gitee(obj);
                break;
            default:
                modelHashMap = webHooksService.gitee(obj);
        }
        log.info("******************** refresh map {}", JSON.toJSONString(modelHashMap));
        webHooksService.zk(modelHashMap);
        return modelHashMap;
    }

}
